using System;
using System.Collections.Generic;

namespace PropertyExpression.PresentationCode.CodeGenerator
{
    class BuilderConfiguration
    {
        private readonly Dictionary<Type, IOverloadedMethodBuilder> overloadedMethodBuilders 
            = new Dictionary<Type, IOverloadedMethodBuilder>();

        private readonly Dictionary<Type, IPrefixMethodBuilder> prefixMethodBuilders
            = new Dictionary<Type, IPrefixMethodBuilder>();

        internal void Add(Type type, IOverloadedMethodBuilder overloadedMethodBuilder, IPrefixMethodBuilder prefixMethodBuilder)
        {
            overloadedMethodBuilders.Add(type, overloadedMethodBuilder);
            prefixMethodBuilders.Add(type, prefixMethodBuilder);
        }

        internal void Add(Type type, IOverloadedMethodBuilder overloadedMethodBuilder)
        {
            overloadedMethodBuilders.Add(type, overloadedMethodBuilder);
        }

        internal void Add(Type type, IPrefixMethodBuilder prefixMethodBuilder)
        {
            prefixMethodBuilders.Add(type, prefixMethodBuilder);
        }

        internal IPrefixMethodBuilder GetPrefixMethodBuilder(Type type)
        {
            IPrefixMethodBuilder value;
            if (prefixMethodBuilders.TryGetValue(type, out value))
            {
                return value;
            }
            else
            {
                return new EmptyPrefixMethodBuilder();
            }
        }

        internal IOverloadedMethodBuilder GetOverloadedMethodBuilder(Type type)
        {
            IOverloadedMethodBuilder value;
            if (overloadedMethodBuilders.TryGetValue(type, out value))
            {
                return value;
            }
            else
            {
                return new EmptyOverloadedMethodBuilder();                
            }
        }

    }
}